package com.dxy.df.core.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * <p>class_name: Paging</p>
 * <p>package: com.dxy.df.core.model</p>
 * <p>describe: 分页</p>
 * <p>@author: wangsheng@dxy.cn</p>
 * <p>@date: 2019-07-25 </p>
 **/
@Setter
@Getter
@ApiModel
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
public class Paging implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(name = "total", value = "总记录数", example = "100")
    @JsonProperty(value = "total")
    private int total;

    @ApiModelProperty(name = "size", value = "每页记录数", example = "10")
    @JsonProperty(value = "size")
    private int size;

    @ApiModelProperty(name = "pages", value = "总页数", example = "10")
    @JsonProperty(value = "pages")
    private int pages;

    @ApiModelProperty(name = "curr_page", value = "当前页数", example = "10")
    @JsonProperty(value = "current")
    private int current;

    /**
     * 分页
     *
     * @param total 总记录数
     * @param size   每页记录数
     * @param current   当前页数
     */
    public Paging(int total, int size, int current) {
        this.total = total;
        this.size = size;
        this.current = current;
        this.pages = (int) Math.ceil((double) total / size);
    }

    public Paging() {
    }
}

